import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/components/home'
import Login from '@/components/login'
import ShopList from '@/components/shop/shop_list'
import ShopAdd from '@/components/shop/shop_add'
import ShopInfoEdit from '@/components/shop/shop_edit'
import CardTypeList from '@/components/card_type/card_type_list'
import CardTypeAdd from '@/components/card_type/card_type_add'
import CardTypeEdit from '@/components/card_type/card_type_edit'
import ClassRoomAdd from '@/components/classroom/classroom_add'
import ClassRoomList from '@/components/classroom/classroom_list'
import ClassRoomEdit from '@/components/classroom/classroom_edit'

// import VuexStore from '../vuex/store'

Vue.use(VueRouter)

export const routes = [
  {
    path: '/login',
    name: 'login',
    component: Login,
    hidden: true
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    hidden: true
  },
  {
    path: '/shop_list',
    name: 'shop_list',
    component: ShopList,
    hidden: true
  },
  {
    path: '/shop_add',
    name: 'shop_add',
    component: ShopAdd,
    hidden: true
  },
  {
    path: '/',
    name: '基本设置',
    component: Home,
    iconType: 'gear-b',
    children: [
      {path: '/card_type_list.vue', component: ShopList, name: '测试列表'},
      {path: '/add', component: ShopAdd, name: '测试表单'},
      {path: '/shop_info_edit', component: ShopInfoEdit, name: '门店'},
      {path: '/card_type_list', component: CardTypeList, name: '卡种'},
      {path: '/card_type_add', component: CardTypeAdd, name: '添加卡类型', hidden: true},
      {path: '/card_type_edit', component: CardTypeEdit, name: '编辑卡类型', hidden: true},
      {path: '/classroom_list', component: ClassRoomList, name: '课室'},
      {path: '/classroom_add', component: ClassRoomAdd, name: '添加课室', hidden: true},
      {path: '/classroom_edit', component: ClassRoomEdit, name: '编辑课室', hidden: true}
    ]
  }
]

export const R = new VueRouter({
  routes
})

// R.beforeEach((to, from, next) => {
//   // if (to.path === '/login') {
//   //   let obj = {}
//   //   obj.logged = false
//   //   // sessionStorage.removeItem('user')
//   //   this.$store.dispatch('is_logged', obj)
//   // }
//   if (!(VuexStore.state.logged) && to.path !== '/login') {
//     next({ path: '/login' })
//   } else {
//     next()
//   }
//   // let user = JSON.parse(sessionStorage.getItem('user'))
//   // if (!user && to.path !== '/login') {
//   //   next({ path: '/login' })
//   // } else {
//   //   next()
//   // }
// })

export default R
